<template>
  <div class="nav-back-wrap">
    <div class="content">
      <span
        class="nav-back"
        :style="{backgroundImage:`url('${backIco}')`}"
        @click="navTo"
      ></span>
      <!-- 其他内容,如标题 -->
    </div>
  </div>
</template>

<script>
import backIco from '@/assets/icons/back.png'

export default {
  name: 'nav-back',
  props: ['to'],
  data: () => ({ backIco }),
  methods: {
    navTo() {
      if (this.to) {
        this.$router.push(this.to)
      } else {
        this.$router.back()
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
$size = 40px;

.nav-back-wrap {
  &::before {
    display: block;
    content: '';
    height: $size;
  }
}

.content {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  background-color: #fff;
}

.nav-back {
  position: relative;
  width: $size;
  height: $size;
  background: center / 80% no-repeat;
}
</style>
